import Vue from 'vue'
import App from './App'
import Request from './utils/request.js'
import {
  upload
} from 'utils/upload.js'
import { baseUrl } from './setting.js'
import uView from 'uview-ui'
Vue.use(uView)
// 如此配置即可
uni.$u.config.unit = 'rpx'

// #ifndef VUE3
Vue.prototype.$http = Request.http
Vue.prototype.$upload = upload
Vue.prototype.$baseUrl = baseUrl

import wxSdk from './utils/wxSdk.js'

Vue.prototype.$wxSdk = wxSdk

Vue.config.productionTip = false
Vue.prototype.$preview = (current, imageArr) => {
  uni.previewImage({
    current,
    urls: imageArr,
  })
}
App.mpType = 'app'
const app = new Vue({
  ...App
})

//替换富文本中的图片样式
Vue.prototype.$replace_Rich_text = function (html) {
  let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
    match = match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/, '').replace(/\style='[^']+'/gi, '');
    match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
    match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
    return match;
  });
  newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
    match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
      'max-width:100%;');
    return match;
  });
  newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  newContent = newContent.replace(/\<img/gi,
    '<img style="max-width:100%;height:auto;display:block;margin:0 auto;"');
  return newContent;
}
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif